/**
 * 
 */
package co.gov.medellin.sdep.sisdep.cco.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.cco.exception.SolicitudLocalException;
import co.gov.medellin.sdep.sisdep.cco.exception.SolicitudLocalRuntimeException;
import co.gov.medellin.sdep.sisdep.cco.exception.descriptor.SolicitudLocalMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.SolicitudLocal;
import co.gov.medellin.sdep.sisdep.model.dao.impl.ISolicitudLocalDAOT;

/**
 * @author Usuario
 *
 */
public class SolicitudLocalServiceImpl extends BaseService implements ISolicitudLocalService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private ISolicitudLocalDAOT solicitudLocalDAO;

	/**
	 * 
	 */
	public SolicitudLocalServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(SolicitudLocal solicitudLocal) throws SolicitudLocalException {
		try{
			solicitudLocal.setUsuarioCrea(getPrincipalUser());
			solicitudLocal.setFechaCrea(new Date());
			getSolicitudLocalDAO().insert(solicitudLocal);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new SolicitudLocalException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new SolicitudLocalException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(SolicitudLocal solicitudLocal) throws SolicitudLocalException {
		try{
			solicitudLocal.setUsuarioModifica(getPrincipalUser());
			solicitudLocal.setFechaModifica(new Date());
			getSolicitudLocalDAO().update(solicitudLocal);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(SolicitudLocal solicitudLocal) throws SolicitudLocalException {
		try {
			solicitudLocal.setUsuarioModifica(getPrincipalUser());
			solicitudLocal.setFechaModifica(new Date());
			getSolicitudLocalDAO().delete(solicitudLocal);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, SolicitudLocal solicitudLocal) throws SolicitudLocalException {
		try{
			//return getSolicitudLocalDAO().getAllSolicitudLocalPaginated(start, max, criteria);
			return getSolicitudLocalDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List loadByRadicado(int start,int max, SolicitudLocal solicitudLocal) throws SolicitudLocalException {
		try{
			//return getSolicitudLocalDAO().getAllSolicitudLocalPaginated(start, max, criteria);
			return getSolicitudLocalDAO().loadByRadicado(solicitudLocal);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}	
	
	/**
	 * @return 
	 * 
	 */
	public final List listaCentrosComerciales() throws SolicitudLocalException {
		try{
			//return getSolicitudLocalDAO().getAllSolicitudLocalPaginated(start, max, criteria);
			return getSolicitudLocalDAO().listaCentrosComerciales();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final SolicitudLocal get(long id) throws SolicitudLocalException {
		try{
			return getSolicitudLocalDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new SolicitudLocalRuntimeException(new SolicitudLocalMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public ISolicitudLocalDAOT getSolicitudLocalDAO() {
		return solicitudLocalDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setSolicitudLocalDAO(ISolicitudLocalDAOT solicitudLocalDAO) {
		this.solicitudLocalDAO = solicitudLocalDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
